data4.14<-read.csv("C:/Users/Administrator/Desktop/lianxi4.14.csv",fileEncoding ="GBK")
data4.14
#1用普通最小二乘法建立回归方程
lm4.14<-lm(y~x1+x2,data=data4.14)
summary(lm4.14)
#检验自相关性
#残差图
e<-resid(lm4.14)
attach(data4.14)
plot(x1+x2,e)
abline(h=c(0),lty=5)
detach(data4.14)
#DW检验
install.packages("lmtest")
library(lmtest)
library(zoo)
dwtest(lm4.14,alternative="two.sided")
#2迭代法，并建立回归方程
newdata4.14<-read.csv("C:/Users/Administrator/Desktop/习题4.14.1.csv",fileEncoding ="GBK")
newdata4.14
lm4.14new<-lm(yy~xx1+xx2,data = newdata4.14)
summary(lm4.14new)
library(lmtest)
library(zoo)
dwtest(lm4.14new,alternative="two.sided")
#3一阶差分法，并建立回归方程
new1data4.14<-read.csv("C:/Users/Administrator/Desktop/习题4.14.2.csv",fileEncoding ="GBK")
new1data4.14
dlm<-lm(dy~dx1-1,data = new1data4.14)
summary(dlm)
dwtest(dlm,alternative="two.sided")
de<-resid(dlm)
de

